package com.lzq.TEST;
import com.lzq.AQS.AQS;

import java.util.ArrayList;
import java.util.List;

public class AQSTest {

    //共享变量
    private static int count = 0;
    //创建手写的锁
    private static AQS syn = new AQS();
    //线程执行的方法
    public void m() {
        syn.lock();
        for (int i = 0; i < 100000; i++) {
            count++;
        }
        syn.unlock();
    }

    public static void main(String[] args) {

        AQSTest t=new AQSTest();
        List<Thread> threads=new ArrayList<>();

        //创建10个线程，并执行m方法
        for (int i = 0; i < 10; i++) {
            threads.add(new Thread(t::m,"thread-"+i));
        }

        threads.forEach((o)->o.start());

        threads.forEach((o)->{
            try {
                o.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        System.out.println(count);
    }

}
